import sys,os,cgi,time
sys.path.insert(0, os.path.split(sys.path[0])[0])
import cfg

query = os.getenv("QUERY_STRING",'') 
kwargs = cgi.parse_qs(query)
hint = kwargs.get('hint',['1'])[0]

kind = os.getenv('AUTH_TYPE','')
user = os.getenv('REMOTE_USER','')
password = os.getenv('REMOTE_PASS','')
value = os.getenv('AUTH_VALUE','')

def authorized(user,password,realm=""):
	return password and user # TODO

if authorized(user,password):
	print "HTTP/1.1 200 ok"
	print 'WWW-Authenticate: Basic realm="rivulet"'
	print "Content-Type: text/html"
	print 
	print "<html><body><h1>hello %s</h1></body><html>" % user
else:
	print "HTTP/1.1 401 Unauthorized"
	print 'WWW-Authenticate: Basic realm="rivulet"'
	print "Content-Type: text/html"
	print
